<?php
namespace Admin\Controller\Goods;
use Admin\Controller\Auto\AutoController;
class OrderController extends AutoController {
	public function index(){
		$this->display();
	}
	public function limit(){
		$order = M('g_order');
		$where['a.bianhao'] = array('like',"%".I('get.keyword')."%");
		$count = M('g_order')->alias('a')->where($where)->count();
		$num = $count/I('get.mylimit');
		$limit = (I('get.ilimit')-1)*I('get.mylimit');
		$list = $order->alias('a')
			->field(array('a.*,b.zhuzhi,b.name,b.phone'))
			->join('left join think_g_address b on a.aid=b.id')
			->where($where)
			->where($where)
			->order('id')
			->limit($limit.','.I('get.mylimit'))
			->select();
		foreach($list as &$list_v){
			$list_v['time']=date('Y-m-d H:i:s',$list_v['time']);
			$list_v['cart']=$gid;
		}
		$list[count($list)]=ceil($num);
		// echo '<pre>';
		// print_r($list);
		// var_dump(null);die;
		// $this->orders = $list;
		$this->AjaxReturn($list);
	}
	public function cart(){
		// echo 'yes';
		// var_dump($_POST);
		$gid = I('post.gid');
		$data = [];
		foreach($gid as $gid_v){
			// var_dump($v);
			$data[] = M('g_cart')->alias('a')
								->field(array('a.*,b.goods_name,b.goods_price,b.goods_stock,b.pinpai'))
								->join('left join think_g_goods b on a.gid=b.id')
								->where('a.id='.$gid_v)
								->find();
		}
		$pic = M('g_goods_pic')->select();
		foreach($data as &$v){
			foreach($pic as $val){
				if($v['gid']==$val['gid'] && $val['goods_zpic']=='1'){
					$v['pic']=$val['goods_pic'];
					$v['subtotal']=$v['num']*$v['goods_price'];
				}
			}
		}
		$this->AjaxReturn($data);
	}
	public function status(){
		// echo 'yes';
		if(M('g_order')->where('id='.I('post.id'))->save(['status'=>1])){
			echo 'yes';
			return ;
		}else{
			echo 'no';
			return ;
		}
	}
}